package cn.jhz.learn.blog.component;

import cn.jhz.learn.blog.po.blogger.BlogBlogger;
import com.sun.org.apache.xpath.internal.operations.Bool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class  ValidationHolder {
    private ValidationHolder(){}

    private static final ThreadLocal<BlogBlogger> userHolder = new ThreadLocal<>();

    private static final ThreadLocal<Map<String, Object>> paramHolder = new ThreadLocal<>();

    private static final ThreadLocal<Map<String, List<Byte>>> resourceLevel = new ThreadLocal<>();

    public static BlogBlogger getCurrentUser(){
        return userHolder.get();
    }

    public static Object getParam(String key){
        return paramHolder.get().get(key);
    }

    public static void setUserHolder(BlogBlogger blogger){
        userHolder.set(blogger);
    }

    public static void setParamHolder(){
        paramHolder.set(new HashMap<>());
        resourceLevel.set(new HashMap<>());
    }

    public static void putParam(String key, Object param){
        paramHolder.get().put(key, param);
    }

    public static List<Byte> getLevel(String key) {
        return resourceLevel.get().get(key);
    }

    public static void putLevel(String key, List<Byte> level){
        resourceLevel.get().put(key, level);
    }

    public static void remove(){
        userHolder.remove();
        paramHolder.remove();
        resourceLevel.remove();
    }
}
